package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.TravellingExpense;

public class TravellingExpenseDAOImpl extends BaseHibernateDAOImpl<TravellingExpense> implements TravellingExpenseDAO {

	public TravellingExpense getTravellingExpenseByTravellingExpenseID(String teID) {
		TravellingExpense travellingExpense;
		try {
			travellingExpense = (TravellingExpense) getSession().get(TravellingExpense.class, teID);

		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return travellingExpense;
	}

	@SuppressWarnings("unchecked")
	public List<TravellingExpense> getAllTravellingExpenseByCondition(String hql) {
		List<TravellingExpense> travellingExpenses;
		try {
			Query query = getSession().createQuery("from TravellingExpense" + hql);
			travellingExpenses = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return travellingExpenses;
	}

	@SuppressWarnings("unchecked")
	public List<TravellingExpense> getAllTravellingExpenseByConditionByPage(String hql, int currentPage, int lineSize) {
		List<TravellingExpense> travellingExpenses;
		try {
			Query query = getSession().createQuery("from TravellingExpense" + hql);
			query.setFirstResult((currentPage - 1) * lineSize);
			query.setMaxResults(lineSize);
			travellingExpenses = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return travellingExpenses;
	}

}
